<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>订单修改</title>
<base>
<link rel="stylesheet" type="text/css"
	href="../../layui/css/layui.css" media="all">
<style type="text/css">
	body{
		margin:20px 0px;
	}
	#one{
		position:absolute;
		right:45%;
		top:65px;
	}
	.demoTable{
		margin:0px 0px 0px 25px;
	}
	.demoTables{
		margin:0px 0px 0px 25px;
	}
</style>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>修改订单</legend>
	</fieldset>

	<form class="layui-form" action="../../FdPurchase/update.action" method="post">
		<div class="layui-form-item">
			<input type="hidden" name="fdPoId" id="fdPoId">
			<input type="hidden" name="manId" id="manId" >
			<input type="hidden" name="fdPoPerson" id="fdPoPerson">
			<input type="hidden" name="fdSunnum" id="fdSunnum">
			<input type="hidden" name="fdSumprice" id="fdSumprice">
			<div class="layui-inline">
				<label class="layui-form-label">采购备注</label>
				<div class="layui-input-inline">
					<input type="text" name="fdPoRemark" id="fdPoRemark" required
						lay-verify="required" placeholder="采购备注" maxlength="200"
						autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-input-block" id="one">
				<input type="submit" class="layui-btn" lay-submit=""
					lay-filter="Add" value="立即修改">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
	<script src="../../layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript">
		
		layui.use('form', function(){
			  var form = layui.form
			  ,layer = layui.layer
			  ,$ = layui.$;
			  
			  form.render('select','selFilter'); 
			  
			  form.on('submit(Add)',function(){
				  parent.location.reload();
			  });

			});
	</script>
	<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
	<script src="../../res/mln/getUrlParam.js"></script>
	<div class="demoTable">
	  搜索药品名称：
	  <div class="layui-inline">
	    <input class="layui-input" name="drugName" id="drugName" autocomplete="off">
	  </div>
	  <button class="layui-btn" data-type="reload" id="search">搜索</button>
	</div>
	<table class="layui-hide" id="goods" lay-filter="demo"></table>
 	<br/>
 	<div class="demoTables">
	  搜索：
	  <div class="layui-inline">
	    <input class="layui-input" name="drugName" id="drugName" autocomplete="off" placeholder="输入药品关键字">
	  </div>
	  <div class="layui-inline layui-form">
			<select name="dtId" id="dtId"
				autocomplete="off" class="layui-input">
				<option></option>
			</select>
	  </div>
	  <div class="layui-inline">
	    <input class="layui-input" name="drugBarCode" id="drugBarCode" autocomplete="off" placeholder="输入药品编码">
	  </div>
	  <div class="layui-inline">
	    <input class="layui-input" name="drugPinyin" id="drugPinyin" autocomplete="off" placeholder="输入药品简称">
	  </div>
      <div class="layui-input-inline" style="width: 100px;">
        <input type="number" id="priceMin" name="priceMin" onkeyup="priceMin()" placeholder="￥" autocomplete="off" class="layui-input">
      </div>
      -
      <div class="layui-input-inline" style="width: 100px;">
        <input type="number" id="priceMax" name="priceMax" onkeyup="priceMax()"   placeholder="￥" autocomplete="off" class="layui-input">
      </div>
	  <button class="layui-btn" data-type="reload">搜索</button>
	  <div class="layui-btn-group demoTable">
  		  <button class="layui-btn" data-type="getCheckData" id="add">确认添加</button>
	  </div>
	</div>
 	<table class="layui-table" id='cx' lay-filter="test"></table>
	<script type="text/html" id="barDemo">
  		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
	<script>
		var arr = "";
		layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
		  var laydate = layui.laydate //日期
		  ,laypage = layui.laypage //分页
		  layer = layui.layer //弹层
		  ,table = layui.table //表格
		  ,upload = layui.upload //上传
		  ,element = layui.element; //元素操作
		  
		  //监听Tab切换
		  element.on('tab(demo)', function(data){
		    layer.msg('切换了：'+ this.innerHTML);
		    console.log(data);
		  });
			//执行一个 table 实例
			  table.render({
			     elem: '#goods'
			    ,url: '../../FdPoBreakdown/findById.action?fdPoId='+getUrlParam("fdPoId") //数据接口
			    ,page: true //开启分页
			    ,method:'post'
			    ,size:'sm'
			    ,cols: [[ //表头
			       {type:'checkbox', fixed: 'left'}
			      ,{field: 'fdPodId', title: '采购明细ID', width:120, fixed: 'left'}
			      ,{field: 'fdPoId', title: '采购订单号', width:120}
			      ,{field: 'drugName', title: '采购药品名称', width:150}
			      ,{field: 'fdItemNumber', title: '物品数量', width:120,edit:'text',sort:"true"}
			      ,{field: 'fdSubtotal', title: '小计', width: 120}
			      ,{field: 'fdItemRemark', title: '物品备注', width: 150,edit:'text',}
			      ,{field: 'fdUnit', title: '物品单位', width: 120}
			      ,{field: 'fdPrice', title: '进价', width: 120}
			      ,{fixed: 'right',title: '操作', width: 140, align:'center', toolbar: '#barDemo'}
			    ]]
			  	,id: 'testReload'
			  });
		  
			//执行一个 table 实例
			  table.render({
			     elem: '#cx'
			    ,url: '../../DrugModel/dindanfindAll.action' //数据接口
			    ,page: true //开启分页
			    ,method:'post'
			    ,size:'sm'
			    ,cols: [[ //表头
			       {type:'checkbox',fixed: 'left'}
			      ,{field: 'drugId', title: '药品ID', width:120, fixed: 'left'}
			      ,{field: 'drugImg', title: '药品图片', width:120,templet:'<div><img src="{{ d.drugImg}}"></div>'}
			      ,{field: 'drugBarCode', title: '药品条形码', width:120}
			      ,{field: 'drugName', title: '药品名称', width:150}
			      ,{field: 'drugPrice', title: '价格', width: 120}
			      ,{field: 'isva', title: '是否有效', width: 120}
			      ,{field: 'pov', title: '单位', width: 120}
			      ,{field: 'dom', title: '研制日期', width: 120}
			      ,{field: 'drugPrices', title: '建议零售价', width: 120}
			      ,{field: 'drugPinyin', title: '汉语拼音简拼', width: 120}
			      ,{field: 'dtName', title: '类型名称', width: 120}
			      ,{field: 'speIndications', title: '适应症', width: 120}
			    ]]
			 	 ,id: 'testRe'
			  });
			  var $ = layui.$, active = {
				    getCheckData: function(){ //获取选中数据
				      var checkStatus = table.checkStatus('testRe')
				      ,data = checkStatus.data;
				      arr = "";
				      arr = arr+JSON.stringify(data);
				    }
				  };
			  
			  $('#add').on('click', function(){
				    var type = $(this).data('type');
				    active[type] ? active[type].call(this) : '';
				    if(arr == "[]"){
			            layer.msg('亲，您还没有选中药品哦!!!', {
	       				  	icon: 5,
	       				  	time: 2000 //1秒关闭（如果不配置，默认是3秒）
	       					}, function(){
	       				  
	       				 });
			        }else{
			        	$.ajax({
		                    url:"../../FdPoBreakdown/add.action",
		                    data:{"arr":arr,"fdPoId":getUrlParam("fdPoId")},
		                    type: "post",
		                    dataType:"json",
		                    cache:false,
		                    async: false,
		                    success: function(obj){
		                    	table.reload('testReload',{
		        					page: {
		        					    curr: 1 //重新从第 1 页开始
		        					  }
		        				});
		                    }
		                 });
			        }
				});
			
		  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
			    var data = obj.data //获得当前行数据
			    ,layEvent = obj.event; //获得 lay-event 对应的值
			    if(layEvent === 'del'){
			      var id=data.fdPodId;
			    
			      layer.confirm('确认删除？', function(index){
			        obj.del(); //删除对应行（tr）的DOM结构
			        layer.close(index);
			        //使用jquery的ajax方式向后台提交数据
					var url = "../../FdPoBreakdown/delete.action";
					var data={fdPodId:id};
						$.post(url,data,function(data){
							
							if(data=="ok"){
								layer.msg('删除成功', {
									  icon: 1,
									  time: 1000 //1秒关闭（如果不配置，默认是3秒）
									}, function(){
									  
								});
								table.reload('testReload',{
									page: {
									    curr: 1 //重新从第 1 页开始
									  }
								});
							}
							
						});
			      	});
			    }
			  });
			//条件查询
			  var $ = layui.$;
					  
			  $('#search').on('click', function(){
				 var matName = $('#drugName');
				 //执行重载
			     table.reload('testReload', {
			       page: {
			         curr: 1 //重新从第 1 页开始
			       }
			       ,where: {
			    	   drugName: matName.val()
			       }
			     });
			  });
			  //条件查询
			  var $ = layui.$;
					  
			  $('.demoTables .layui-btn').on('click', function(){
				 var drugName = $('#drugName');
				 var dtId = $('#dtId');
				 var drugBarCode = $('#drugBarCode');
				 var drugPinyin = $('#drugPinyin');
				 var priceMin = $('#priceMin');
				 var priceMax = $('#priceMax');
				 //执行重载
			     table.reload('testRe', {
			       page: {
			         curr: 1 //重新从第 1 页开始
			       }
			       ,where: {
			    	   drugName: drugName.val(),
			    	   dtId:dtId.val(),
			    	   drugBarCode:drugBarCode.val(),
			    	   drugPinyin:drugPinyin.val(),
			    	   priceMin:priceMin.val(),
			    	   priceMax:priceMax.val()
			       }
			     });
			  });
			//监听单元格编辑
			  table.on('edit(demo)', function(obj){
			    var value = obj.value //得到修改后的值
			    ,data = obj.data //得到所在行所有键值
			    ,field = obj.field; //得到字段
			    var fdItemNumber;
			    var fdItemRemark;
			    if(field=="fdItemNumber"){
			    	var reg = new RegExp("^[0-9]*$");  
			    	if(reg.test(value)){
			    		fdItemNumber=value;
				    	fdItemRemark=data.fdItemRemark;
			    	}else {
			    		
			    		layer.msg('输入的内容不能含有字母或文本', {
							  icon: 1,
							  time: 1000 //1秒关闭（如果不配置，默认是3秒）
							}, function(){
								table.reload('testReload',{page:{curr:1}});
						});
			    		return;
			    	}
			    	
			    }else if(field=="fdItemRemark"){
			    	fdItemRemark=value;
			    	fdItemNumber=data.fdItemNumber;
			    }
			    var fdPodId=data.fdPodId;
			    var fdPrice=data.fdPrice;
		    	$.ajax({
		            url:"../../FdPoBreakdown/update.action",
		            data:{"fdPodId":fdPodId,"fdPrice":fdPrice,"fdItemRemark":fdItemRemark,"fdItemNumber":fdItemNumber},
		            type: "post",
		            dataType:"json",
		            cache:false,
		            async: false,
		            success: function(obj){
						table.reload('testReload',{
							page: {
							    curr: 1 //重新从第 1 页开始
							  }
						});
		            }
		         });
			  });
		});
	</script>
</body>
</html>